package com.util;

import com.javabean.User;
import mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class UserMapperTest {
    SqlSessionFactory sqlSessionFactory;
    SqlSession sqlSession;
    UserMapper mapper;

    @Before
    public void before() {
        sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();
        sqlSession = sqlSessionFactory.openSession(true);
        mapper = sqlSession.getMapper(UserMapper.class);
    }

    @After
    public void after() {
        sqlSession.close();
    }

    @Test
    public void selectAll(){
        for (User user : mapper.selectAll()) {
            System.out.println(user);
        }
    }
    @Test
    public void selectUser(){
        User u=new User(5,"tzsb",null,"hbzsb");
        for (User user : mapper.selectUser(u)) {
            System.out.println(user);
        }
    }

    @Test
    public void selectU_R(){
        for (User user : mapper.selectU_R()) {
            System.out.println(user);
        }
    }

}
